package com.lizard.schedule.persistence.db.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.lizard.schedule.log.ScheduleLog;

/**
 * ScheduleTbl bean
 */
public class Schedule implements Cloneable, Parcelable {

    /**
     * 状态：未结束
     */
    public static int STATUS_UNFINISHED = 1;

    /**
     * 状态：结束
     */
    public static int STATUS_FINISHED = 2;

    /**
     * server id 的默认值
     */
    public static int SERVER_ID_DEFAULT = -1;

    /**
     * 本地id
     */
    private int localId;

    /**
     * 文本内容
     */
    private String contentText;

    /**
     * server里面的该条记录id
     */
    private long serverId;

    /**
     * 计划开始时间
     */
    private long beginTime;

    /**
     * 状态
     */
    private int status = STATUS_UNFINISHED;

    /**
     * 是否删除
     */
    private boolean deleted = false;

    /**
     * 是否提交到server
     */
    private boolean submited = false;

    /**
     * 重复
     */
    private int repeat;

    public Schedule() {
    }

    public Schedule(int localId, String contentText, long serverId, long beginTime, int status, boolean deleted, boolean submited, int repeat) {
        this.localId = localId;
        this.contentText = contentText;
        this.serverId = serverId;
        this.beginTime = beginTime;
        this.status = status;
        this.deleted = deleted;
        this.submited = submited;
        this.repeat = repeat;
    }

    public long getServerId() {
        return serverId;
    }

    public void setServerId(long serverId) {
        this.serverId = serverId;
    }

    public String getContentText() {
        return contentText;
    }

    public void setContentText(String contentText) {
        this.contentText = contentText;
    }

    public long getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(long beginTime) {
        this.beginTime = beginTime;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public boolean isSubmited() {
        return submited;
    }

    public void setSubmited(boolean submited) {
        this.submited = submited;
    }

    public int getLocalId() {
        return localId;
    }

    public void setLocalId(int localId) {
        this.localId = localId;
    }

    public int getRepeat() {
        return repeat;
    }

    public void setRepeat(int repeat) {
        this.repeat = repeat;
    }

    @Override
    public Object clone() {
        Object object = null;
        try {
            object = super.clone();
        } catch (CloneNotSupportedException e) {
            ScheduleLog.e("Schedule is not cloneable");
        }
        return object;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeInt(localId);
        parcel.writeString(contentText);
        parcel.writeLong(serverId);
        parcel.writeLong(beginTime);
        parcel.writeInt(status);
        parcel.writeByte((byte) (deleted ? 1 : 0));
        parcel.writeByte((byte) (submited ? 1 : 0));
        parcel.writeInt(repeat);
    }

    public static final Parcelable.Creator<Schedule> CREATOR = new Creator<Schedule>() {

        @Override
        public Schedule createFromParcel(Parcel parcel) {
            Schedule schedule = new Schedule();
            schedule.setLocalId(parcel.readInt());
            schedule.setContentText(parcel.readString());
            schedule.setServerId(parcel.readLong());
            schedule.setBeginTime(parcel.readLong());
            schedule.setStatus(parcel.readInt());
            schedule.setDeleted(parcel.readByte() != 0);
            schedule.setSubmited(parcel.readByte() != 0);
            schedule.setRepeat(parcel.readInt());
            return schedule;
        }

        @Override
        public Schedule[] newArray(int i) {
            return new Schedule[i];
        }
    };
}
